package controller

import (
	"communityTopics/service"
	"strconv"
)

func PostPublish(userIdStr string, topicIdStr string, rootIdStr string, content *string) *PageData {
	uid, err := strconv.ParseInt(userIdStr, 10, 64)
	if err != nil {
		return &PageData{
			Code: -1,
			Msg:  err.Error(),
		}
	}
	tid, err := strconv.ParseInt(topicIdStr, 10, 64)
	if err != nil {
		return &PageData{
			Code: -1,
			Msg:  err.Error(),
		}
	}
	rid, err := strconv.ParseInt(rootIdStr, 10, 64)
	if err != nil {
		return &PageData{
			Code: -1,
			Msg:  err.Error(),
		}
	}
	data, err := service.PostPublish(uid, tid, rid, content)
	if err != nil {
		return &PageData{
			Code: -1,
			Msg:  err.Error(),
		}
	}
	return &PageData{
		Code: 0,
		Msg:  "success",
		Data: data,
	}
}
